package com.atguigu.bean.service.impl;

import com.atguigu.bean.bean.User;
import com.atguigu.bean.dao.UserDao;
import com.atguigu.bean.dao.impl.UserDaoImpl;
import com.atguigu.bean.service.UserService;

/**
 * Date:2020/9/7
 * Author:ybc
 * Description:
 */
public class UserServiceImpl implements UserService {

    UserDao userDao = new UserDaoImpl();

    @Override
    public User login(String username, String password) {
        return userDao.login(username, password);
    }

    @Override
    public boolean regist(User user) {
        //先验证用户名是否可用
        User userBySQL = userDao.checkUsername(user.getUsername());
        //将通过sql查询出的user对象和mull进行比较
        if(userBySQL == null){
            //通过用户名未查询出数据，说明用户名可用，则直接实现自注册功能，注册成功
            userDao.registUser(user);
            return true;
        }else{
            //通过用户名查询出了数据，说明用户名已经被注册，不可用，注册失败
            return false;
        }
    }
}
